﻿using IterationLife.Domains.Sports.Models;
using Util.Datas.Ef;

namespace IterationLife.Datas.Mappings.Sports
{
    /// <summary>
    /// 运动员映射配置
    /// </summary>
    public class SportAthleteMap : AggregateRootMapBase<SportAthlete>
    {
        /// <summary>
        /// 映射表
        /// </summary>
        protected override void MapTable()
        {
            ToTable("SportAthletes", "Sports");
        }

        /// <summary>
        /// 映射属性
        /// </summary>
        protected override void MapProperties()
        {
            //运动员编号
            Property(t => t.Id)
                .HasColumnName("SportAthleteId");
        }

        /// <summary>
        /// 映射导航属性
        /// </summary>
        protected override void MapAssociations()
        {
            //体育队伍
            HasMany(t => t.SportTeams)
                .WithMany(t => t.SportAthletes)
                .Map(m =>
                {
                    m.ToTable("SportAthleteToSportTeams", "Sports");
                    m.MapLeftKey("SportAthleteId");
                    m.MapRightKey("SportTeamId");
                });
        }
    }
}
